package com.oocl.reservedparkingsystembackend.controller;

import com.oocl.reservedparkingsystembackend.mapper.ParkingSpaceMapper;
import com.oocl.reservedparkingsystembackend.model.dto.ParkingSpaceResponse;
import com.oocl.reservedparkingsystembackend.service.ParkingSpaceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("parking-spaces")
public class ParkingSpaceController {
    private ParkingSpaceService parkingSpaceService;
    private ParkingSpaceMapper parkingSpaceMapper;

    public ParkingSpaceController(ParkingSpaceService parkingSpaceService, ParkingSpaceMapper parkingSpaceMapper) {
        this.parkingSpaceService = parkingSpaceService;
        this.parkingSpaceMapper = parkingSpaceMapper;
    }


    @GetMapping("{id}")
    public List<ParkingSpaceResponse> getParkingSpaceByParkingLotId(@PathVariable String id) {

        return parkingSpaceService.getParkingSpaceByParkingLotId(id).stream()
                .map(parkingSpace -> parkingSpaceMapper.toParkingSpaceResponse(parkingSpace))
                .collect(Collectors.toList());
    }

    @GetMapping("/add")
    public void add() {
        parkingSpaceService.add(null);
    }

}
